#include<bits/stdc++.h>
using namespace std;
set<unsigned long long> s;
int n,a[1009],b[1009];
void dfs(int x,int y,unsigned long long nw){
    // cout<<x<<" "<<y<<' '<<nw<<endl;
    if(x==n&&y==n){
        s.insert(nw);
        return;
    }
    if(x!=n){
        dfs(x+1,y,nw*10+b[y]*1ull);
    }
    if(y!=n){
        dfs(x,y+1,nw*10+a[x]*1ull);
    }
}
int main(){
    freopen("zha.in","r",stdin);
    freopen("zha.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",a+i);
        a[i]--;
    }
    for(int i=1;i<=n;i++){
        scanf("%d",b+i);
        b[i]--;
    }
    if(n<=30)dfs(1,1,0);
    else for(int i=1;i<=n;i++)s.insert(i);
    printf("%ld\n",s.size());
    return 0;
}